package uk.ac.ebi.bioinvindex.model.impl;

import uk.ac.ebi.bioinvindex.model.impl.xref.XrefImpl;

import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Collection;

/**
 *
 * @author brandizi
 */
@MappedSuperclass
public abstract class HasReferencesImpl<T extends XrefImpl> extends AnnotatableImpl {

	private Collection<T> refs = new ArrayList<T>();

	@Transient
	public Collection<T> getXrefs () {
		return this.refs;
	}

	public void addXref ( T ref ) {
		ref.setOwner ( this );
		this.refs.add (  ref );
  }


	protected void setXrefs ( Collection<T> refs ) {
		for ( T ref: refs ) {
			ref.setOwner ( this );
		}
    this.refs = refs;
	}

	public boolean removeXref(XrefImpl xref) {
		return this.refs.remove(xref);
	}
}
